export const dateToString = (date: Date): string => {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};

export const stringToDate = (dateStr: string): Date => {
  const parts = dateStr.split(" ");
  const dateParts = parts[0].split("-");
  const timeParts = parts[1].split(":");

  return new Date(
    parseInt(dateParts[0], 10),
    parseInt(dateParts[1], 10) - 1, // 月份是从 0 开始的
    parseInt(dateParts[2], 10),
    parseInt(timeParts[0], 10),
    parseInt(timeParts[1], 10),
    parseInt(timeParts[2], 10)
  );
};
